package study.js.jvppeteer;

import com.ruiyun.jvppeteer.core.Puppeteer;
import com.ruiyun.jvppeteer.core.browser.Browser;
import com.ruiyun.jvppeteer.core.page.Page;
import com.ruiyun.jvppeteer.options.LaunchOptions;
import com.ruiyun.jvppeteer.options.LaunchOptionsBuilder;
import com.ruiyun.jvppeteer.options.PDFOptions;
import lombok.SneakyThrows;

import java.util.ArrayList;

public class Main2 {

    @SneakyThrows
    public static void main(String[] args) {
        ArrayList<String> argLt = new ArrayList<>();
        argLt.add("--no-sandbox");
        argLt.add("--disable-setuid-sandbox");
        //生成pdf必须在无头模式下才能生效
        LaunchOptions options = new LaunchOptionsBuilder()
                .withArgs(argLt)
                .withHeadless(true)
                .build();

        Browser browser = Puppeteer.launch(options);
        Page page = browser.newPage();
        page.goTo("https://www.cnblogs.com/binbingg/p/15069297.html");
        PDFOptions pdfOptions = new PDFOptions();
        pdfOptions.setPath("d:/test2.pdf");
        page.pdf(pdfOptions);
        page.close();
    }
}
